{template 'public/header'}
{template 'public/comhead'}
<ul class="nav nav-tabs">
    <li {if $operation == 'display' || empty($operation)}class="active"{/if}><a href="{php echo $this->createWebUrl('material', array('op' => 'display', 'storeid' => $storeid))}">物料管理</a></li>
    <li {if $operation == 'post'}class="active"{/if}><a href="{php echo $this->createWebUrl('material', array('op' => 'post', 'storeid' => $storeid))}">添加物料</a></li>
</ul>
{if $operation == 'display'}
<div class="main">
    <div class="panel panel-default">
        <div class="panel-heading">筛选</div>
        <div class="table-responsive panel-body">
            <form action="./index.php" method="get" class="navbar-form navbar-left" role="form">
                <input type="hidden" name="c" value="site" />
                <input type="hidden" name="a" value="entry" />
                <input type="hidden" name="m" value="weisrc_dish" />
                <input type="hidden" name="do" value="material" />
                <input type="hidden" name="op" value="display" />
                <input type="hidden" name="storeid" value="{$storeid}" />
                <div class="form-group">
                    <input type="text" class="form-control" placeholder="物料名称" name="keyword" style="width: 230px;"/>
                </div>
                <button class="btn btn-success"><i class="fa fa-search"></i> 搜索</button>
            </form>
        </div>
    </div>
    <div class="panel panel-default">
        <div class="table-responsive panel-body">
        <form action="" method="post" class="form-horizontal form" >
            <input type="hidden" name="storeid" value="{$storeid}" />
            <table class="table table-hover">
                <thead class="navbar-inner">
                <tr>
                    <th style="width:8%;">ID</th>
                    <th style="width:30%;">名称</th>
                    <th style="width:20%;">供应商</th>
                    <th style="width:20%;">规格</th>

                    <th style="width:10%;">库存</th>
                    <th style="width:10%;text-align:right;">操作</th>
                </tr>
                </thead>
                <tbody id="level-list">
                {loop $list $row}
                <tr>
                    <td>{$row['id']}</td>
                    <td>
                        {if !empty($row['name'])}{$row['name']}{else}------{/if}
                    </td>
                    <td>
                        {$row['company']}
                    </td>
                    <td>{$row['option']}</td>
                    <td>{$row['count']} {$row['unit']}</td>
                    <td style="text-align:right;">
                        <a class="btn btn-default btn-sm" href="{php echo $this->createWebUrl('material', array('op' => 'post', 'id' => $row['id'], 'storeid' => $storeid))}" title="编辑">改</a>
                        <a class="btn btn-default btn-sm" onclick="return confirm('确认删除吗？');return false;"
                           href="{php echo $this->createWebUrl('material', array('id' => $row['id'], 'op' => 'delete', 'storeid' => $storeid))}" title="删除">删</a>
                    </td>
                </tr>
                {/loop}
                </tbody>
            </table>
        </form>
        {$pager}
        </div>
    </div>
</div>
{elseif $operation == 'post'}
<link rel="stylesheet" href="{$_W['siteroot']}addons/weisrc_dish/public/web/css/awesome-bootstrap-checkbox.css">
<div class="main">
    <script type="text/javascript">
        require(['jquery', 'util'], function($, u){
            $('#form1').submit(function(e) {
                if($.trim($(':text[name="name"]').val()) == '') {
                    u.message('没有输入用户名.', '', 'error');
                    return false;
                }
                if($('#storeid option:selected').val() == 0) {
                    u.message('请选择所属门店.', '', 'error');
                    return false;
                }
            });
        });
    </script>
    <form action="" method="post" class="form-horizontal form" enctype="multipart/form-data" id="form1">
        <input type="hidden" name="storeid" value="{$storeid}" />
        <div class="panel panel-default">
            <div class="panel-heading">
                添加新物料
            </div>
            <div class="panel-body">
                <div class="form-group">
                    <label class="col-xs-12 col-sm-2 col-md-2 col-lg-2 control-label"><span class="require">*</span>名称</label>
                    <div class="col-sm-10 col-lg-9">
                        <input type="text" name="name" class="form-control" value="{$reply['name']}" />
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-xs-12 col-sm-2 col-md-2 col-lg-2 control-label"><span class="require">*</span>单位</label>
                    <div class="col-sm-10 col-lg-9">
                        <input type="text" name="unit" class="form-control" value="{$reply['unit']}" />
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-xs-12 col-sm-2 col-md-2 col-lg-2 control-label"><span class="require">*</span>规格</label>
                    <div class="col-sm-10 col-lg-9">
                        <input type="text" name="option" class="form-control" value="{$reply['option']}" />
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-xs-12 col-sm-2 col-md-2 col-lg-2 control-label"><span class="require">*</span>进货价格</label>
                    <div class="col-sm-10 col-lg-9">
                        <input type="text" name="price" class="form-control" value="{$reply['price']}" />
                    </div>
                </div>
               <div class="form-group">
                <label class="col-xs-12 col-sm-3 col-md-2 control-label">供应商</label>
                <div class="col-sm-9">
                    <select class="form-control" name="supplierid" id="supplierid">
                        <option value="0">请选择</option>
                        {loop $supplier $item}
                        <option value="{$item['id']}" {if $reply['supplierid']==$item['id']}selected{/if}>{$item['company']}</option>
                        {/loop}
                    </select>
                    <div class="help-block">
                        还没有供应商，点我 <a href="{php echo $this->createWebUrl('supplier', array('op' => 'post', 'storeid' => $storeid))}"><i class="fa fa-plus-circle"></i> 添加供应商</a>
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-xs-12 col-sm-2 col-md-2 col-lg-2 control-label"><span class="require">*</span>产地</label>
                    <div class="col-sm-10 col-lg-9">
                        <input type="text" name="address" class="form-control" value="{$reply['address']}" />
                    </div>
                </div>
            </div>
            </div>
        </div>
        <div class="form-group col-sm-12">
            <input type="submit" name="submit" value="保存设置" class="btn btn-primary col-lg-3" />
            <input type="hidden" name="token" value="{$_W['token']}" />
        </div>
    </form>
</div>
{template 'web/_modal_fans'}
{/if}
{template 'common/footer'}